var fs = require("fs");
var _ = require("lodash");

let fileNameC = "Client_Monster";
let fileName1 = "./data/skill4";
let fileName2 = "MonsterDes";
let outputFileName = "./data/monster.json";

let mainData = JSON.parse(fs.readFileSync(`${fileNameC}.json`).toString()).map;
let skill2 = JSON.parse(fs.readFileSync(`${fileName1}.json`).toString());
let monDes = JSON.parse(fs.readFileSync(`${fileName2}.json`).toString()).map;

let skillMap = new Map();
let monDesMap = new Map();
_.forEach(skill2, (e) => {
  let id = e.id;
  let data = e.data;
  skillMap.set(id, data);
});
_.forEach(monDes, (e) => {
  let id = e.id;
  let data = e.data;
  monDesMap.set(id, data);
});
_.forEach(mainData, (e) => {
  e.data.abilities = _.map(e.data.abilities, (obj) => {
    if (skillMap.has(obj)) {
      obj = skillMap.get(obj);
    }
    return obj;
  });
  _.forEach(e.data.hpStage, (obj) => {
    if (obj.skills) {
      _.forEach(obj.skills.specialAbilitys, (x) => {
        if (skillMap.has(x.skillId)) {
          x = _.assign(x, skillMap.get(x.skillId));
        }
      })
    }
  });
  let id = e.data.id;
  if (monDesMap.has(id)) {
    _.assign(e.data, monDesMap.get(id));
  }
});

fs.writeFileSync(outputFileName, JSON.stringify(mainData));
